<template>
	<view class="register">

		<view class="content">
			<!-- 头部logo -->
			<view class="header">
				<image :src="logoImage"></image>
			</view>
			<!-- 主体 -->
			<view class="main">
				<wInput v-model="phoneData" type="text" maxlength="11" placeholder="账号"></wInput>
				<wInput v-model="passData" type="password" maxlength="11" placeholder="密码" isShowPass></wInput>
        <!-- <wInput
					v-model="verCode"
					type="number"
					maxlength="4"
					placeholder="验证码"
					isShowCode
					:codeText="codeText"
					ref="runCode"
					@setCode="getVerCode()"
				></wInput> -->
			</view>

			<wButton class="wbutton" text="注 册" :rotate="isRotate" @click.native="startReg()"></wButton>

			<!-- 底部信息 -->
			<view class="footer">
				<navigator url="login" open-type="navigate">已有账号，点击登录</navigator>
				<!-- <text @tap="isShowAgree" class="cuIcon" :class="showAgree?'cuIcon-radiobox':'cuIcon-round'"> 同意</text>
				<navigator url="" open-type="navigate">《协议》</navigator> -->
			</view>
		</view>
	</view>
</template>

<script>
	let _this;
import wInput from '../../components/watch-login/watch-input.vue' //input
import wButton from '../../components/watch-login/watch-button.vue' //button
import { navigateBack } from '../../static/utils';

	export default {
		data() {
			return {
				//logo图片 base64
				logoImage: '',
				phoneData: '', // 用户/电话
				passData: '', //密码
				verCode: "", //验证码
				showAgree: true, //协议是否选择
				isRotate: false, //是否加载旋转
				codeText:"",
			}
		},
		components: {
			wInput,
			wButton,
		},
		mounted() {
			_this = this;
			// this.getVerCode()
		},
		methods: {
			getVerCode(){
				//获取验证码
				uni.request({
					url: 'https://api.uuni.cn/api/yzm',
					data: {
						length: 4,
					},
					success: (res) => {
						console.log('res', res)
						this.codeText = res.data.verification_code
					},
				})
			},
			isShowAgree() {
				//是否选择协议
				_this.showAgree = !_this.showAgree;
			},
			startReg() {
				//注册
				if (this.isRotate) {
					//判断是否加载中，避免重复点击请求
					return false;
				}
				if (this.phoneData.length == 0) {
					uni.showToast({
						icon: 'none',
						position: 'bottom',
						title: '请输入账号'
					});
					return false;
				}
				if (this.passData.length < 6) {
					uni.showToast({
						icon: 'none',
						position: 'bottom',
						title: '密码需要大于6位'
					});
					return false;
				}
				// if (this.verCode != this.codeText) {
				// 	uni.showToast({
				// 		icon: 'none',
				// 		position: 'bottom',
				// 		title: '验证码错误！'
				// 	});
				// 	return false;
				// }
				
				_this.isRotate = true
				uni.showLoading({
					title: '注册中'
				});
				uni.request({
					url: 'https://fc-mp-fff067d4-0ad0-46f1-8940-3076faaf2173.next.bspapp.com/register',
					data: {
						phoneData: this.phoneData,
						passData: this.passData,
					},
					success: (res) => {
						console.log('res', res)
						if(res.data.code==200){
							 uni.showToast({
							 	icon: 'success',
							 	title: '注册成功'
							 });
							 navigateBack(1)
						}
					},
					complete: () => {
						uni.hideLoading();
						_this.isRotate = false
					}
				})
			}
		}
	}
</script>

<style>
	@import url("../../components/watch-login/css/icon.css");
	@import url("./css/main.css");
</style>
